package MCM;

import java.util.Scanner;

public class main {
	public static void main(String[] args) {
		int n = 5;//矩阵数量
		int[] p = {10,15,20,25,30,35};//矩阵边长
	    int[][] m = new int[n+1][n+1];//记录第i到j个矩阵最优解
	    int[][] s = new int[n+1][n+1];//记录
        
        dynamicProgramming server = new dynamicProgramming(n,m,s,p);
        //server.run();
        server.runOther(1, n);
        System.out.println("最终的矩阵");
        server.printM();
        print(1, server.n,s);
        System.out.printf(" %d\n", server.m[1][n]);
	}
	
	public static void print(int i, int j,int[][] s)
    {
        if (i == j)
            System.out.print("A" + i);
        else
        {
            System.out.print("(");
            print(i, s[i][j],s);
            print(s[i][j] + 1, j,s);
            System.out.print(")");
        }
    }
}
